Using Web Service in Java [deprecated]
This is a short example for a JAVA web service call.
Before you begin
We created a working example on March 2007 using the following prerequisites:
- The Java WS client is based on the Apache AXIS soap toolkit
- The Java SDK used here is j2 sdk 1.4.2_13
About this task
Presuming you have the prerequisites installed:
- Create a file named
InfoShareWSTester.javawith the following contentimport java.util.Iterator; import java.util.List; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; public class InfoShareWSTester { public static void main(String[] args) { InfoShareWSTester t = new InfoShareWSTester(); t.getVersion(); t.login(); } public String getVersion() { try { Service service = new Service(); Call call = (Call) service.createCall(); String endpoint = "http://localhost/ISHWS/application.asmx?wsdl"; call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true)); call.setProperty(Call.SOAPACTION_URI_PROPERTY, "urn:trisoft.be:WebServices:InfoShare:Application:1.0/GetVersion"); QName qn = new QName("urn:trisoft.be:WebServices:InfoShare:Application:1.0", "GetVersion"); call.setOperationName(qn); String version = (String)call.invoke(new Object[] {}); System.out.println(version); return version; } catch (Exception e) { System.err.println(e.toString()); } return null; } public String login() { try { Service service = new Service(); Call call = (Call) service.createCall(); String endpoint = "http://localhost/ISHWS/application.asmx?wsdl"; call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true)); call.setProperty(Call.SOAPACTION_URI_PROPERTY, "urn:trisoft.be:WebServices:InfoShare:Application:1.0/Login"); QName qn = new QName("urn:trisoft.be:WebServices:InfoShare:Application:1.0", "Login"); call.setOperationName(qn); call.addParameter(new QName("urn:trisoft.be:WebServices:InfoShare:Application:1.0", "psApplication"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("urn:trisoft.be:WebServices:InfoShare:Application:1.0", "psUserName"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("urn:trisoft.be:WebServices:InfoShare:Application:1.0", "psPassword"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("urn:trisoft.be:WebServices:InfoShare:Application:1.0", "psOutAuthContext"), XMLType.XSD_STRING, ParameterMode.OUT); call.setReturnType(XMLType.XSD_INT); Integer result = (Integer)call.invoke(new String[] {"ISHCM", "Admin", "admin"}); if(result != null && result.intValue() == 0) { List l = call.getOutputValues(); Iterator i = l.iterator(); while(i.hasNext()) { String authContext = (String)i.next(); System.out.println(authContext); return authContext; } } } catch (Exception e) { System.err.println(e.toString()); } return null; } } - Create a file named Compile.bat with the following content
C:\j2sdk1.4.2_13\bin\javac -classpath lib/axis.jar;lib/jax-1_1-fr-qname-class.jar;lib/jaxrpc.jar InfoShareWSTester.java pause - Create a file named Run.bat with the following content
C:\j2sdk1.4.2_13\bin\java -classpath lib/axis.jar;lib/jax-1_1-fr-qname-class.jar;lib/jaxrpc.jar;lib/commons-logging-1.0.4.jar;lib/commons-discovery-0.2.jar;lib/saaj.jar;lib/wsdl4j-1.5.1.jar;lib/activation.jar;lib/mailapi.jar;. InfoShareWSTester pause - Execute Compile.bat and Run.bat